package es.unileon.prg2.patterns.composite;

import es.unileon.prg2.patterns.handler.GenericId;
import es.unileon.prg2.patterns.handler.Handler;

public class Citizen implements Component {

	private Handler id;
	final int level = 5;

	public Citizen(Handler id) {
		this.id = id;
	}

	public Citizen(String id) {
		this(new GenericId(id));
	}

	public Handler getId() {
		return this.id;
	}

	@Override
	public int getLevel() {
		return this.level;
	}

	public int size() {
		return 1;
	}

	public void add(Component c) throws CompositeException {
		throw new CompositeException("Nothing can be added to a leaf");
	}

	public boolean remove(Component c) {
		return false;
	}

	@Override
	public Component search(Handler c) {
		if (this.id.compareTo(c) == 0) {
			return this;
		}
		return null;
	}
	
	public String toString(){
		return "\t\t\t\t\tCitizen: " + this.id.toString() + "\n";
	}
	
}
